<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2020/3/30
 * Time: 13:41
 */
namespace app\admin\controller;
use think\Db;
use think\Request;
class Clubs extends Base {
    public function index(){
        if(request()->isAjax()){
            $club_name = input('club_name');
            $keyword = input('keyword');
            $where = [];
            if(isset($club_name) && $club_name != "")
            {
                $where['a.club_name'] = ['like', '%' . $club_name . '%'];
            }
            if(isset($keyword) && $keyword != "")
            {
                $where['uuu.user_username|uuu.user_phone'] = ['like', '%' . $keyword . '%'];
            }

            $NowPage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::table('up_club_species')->alias('a')
                ->join('up_u_user uuu', 'uuu.user_id = a.user_id', 'left')
                ->join('up_club uc','uc.club_id = a.club_id','left')
                ->where($where)
                ->count();// 获取总条数
            $lists =  Db::table('up_club_species')->alias('a')
                ->join('up_u_user uuu', 'uuu.user_id = a.user_id', 'left')
                ->join('up_club uc','uc.club_id = a.club_id','left')
                ->field('a.*,uc.club_name,uuu.user_username,uuu.user_phone')
                ->page($NowPage,$limits)
                ->order('club_id desc')
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch();
    }



}